<template>
  <div class="app-container" style="width: 1000px">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="开始时间">
        <el-date-picker
          value-format="yyyy-MM-dd HH:mm:ss"
          v-model="queryParams.startTime"
          type="datetime"
          placeholder="选择日期时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间">
        <el-date-picker
          value-format="yyyy-MM-dd HH:mm:ss"
          v-model="queryParams.endTime"
          type="datetime"
          placeholder="选择日期时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
              <el-button
                type="primary"
                plain
                icon="el-icon-plus"
                size="mini"
                @click="handleAdd"
                >新增</el-button
              >
            </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          :disabled="multiple"
          size="mini"
          @click="handleUpdatse"
          >核对</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <!-- <el-button
                  type="danger"
                  plain
                  icon="el-icon-delete"
                  size="mini"
                  :disabled="multiple"
                  @click="handleDelete"
                  >删除</el-button
                > -->
      </el-col>
      <el-col v-if="user == 'admin'" :span="1.5">
        <!-- <el-button
                type="warning"
                plain
                icon="el-icon-download"
                size="mini"
                @click="handleExport"
                >导出</el-button
              > -->
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      v-loading="loading"
      :data="roleList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="日期" width="150" prop="collectionTime" />

      <el-table-column label="退款单号" width="150" prop="orderNumber"> </el-table-column>

      <el-table-column label="退款金额" prop="money" />
      <el-table-column label="退款途径" prop="paymentTerm" />
      <el-table-column label="退款人" prop="payee" />
      <el-table-column label="备注" prop="remark" />
      <el-table-column label="核对" prop="checkStatus">
        <template slot-scope="scope">
          {{ scope.row.checkStatus == 0 ? "" : scope.row.checkStatus }}
        </template>
      </el-table-column>

      <el-table-column
        fixed="right"
        label="操作"
        align="center"
        width="200"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope" v-if="scope.row.complaintId !== 1">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >核对</el-button
          >
          <el-button
                    size="mini"
                    type="text"
                    @click="handleDelete(scope.row)"
                    >备注</el-button
                  >
        </template>
      </el-table-column>
    </el-table>
    <el-dialog @close="guanbishoukan" :title="title" :destroy-on-close="true" :close-on-click-modal="false"
      :visible.sync="yus">
      <el-form :model="srer" :rules="kesuwanfromre" ref="xundanfrom" label-width="180px" class="demo-ruleForm">
      
        <el-form-item prop="customerNickname" label="备注">
          <el-input v-model="srer.remark" placeholder="请输入备注" clearable style="width: 240px"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
      
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button @click="yus = false">取 消</el-button>
        <el-button type="primary" @click="xundan">确 定</el-button>
      </div>
    </el-dialog>
    <pagination
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listRole,
  getRole,
  delRole,
  addRole,
  updateRole,
  dataScope,
  changeRoleStatus,
  deptTreeSelect,
} from "@/api/system/role";
import { deleteixundan, paizneg, xieshou } from "@/api/new";

import { listUser, kethe,addsrenwuj } from "../../api/new";
import {
  treeselect as menuTreeselect,
  roleMenuTreeselect,
} from "@/api/system/menu";

export default {
  name: "Role",
  dicts: ["sys_normal_disable"],
  data() {
    return {
      ketui: "",
      jiaojie: "",
      dai: "",
      // 遮罩层
      loading: true,
      // 选中数组
      xunkong: false,
      ids: [],
      xunkong: false,
      // 非单个禁用
      single: true,
      now: "",
      hounow: 0,
      // 非多个禁用
      kesuwanfrom: {
        recordId: "",
        workDate: "",
        workOne: "",
        workTwo: "",
        restWorker: "",
        remake: null,
      },
      kesuwanfromre: {
        workDate: [
          { required: true, message: "日期不能为空", trigger: "blur" },
        ],
        workOne: [{ required: true, message: "员工不能为空", trigger: "blur" }],
        workTwo: [{ required: true, message: "员工不能为空", trigger: "blur" }],
        restWorker: [
          { required: true, message: "员工不能为空", trigger: "blur" },
        ],
      },
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      yus:false,
      srer:{
        recordId:'',
        remark:''
      },
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      user: this.$store.state.user.name,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      // 数据范围选项

      yiwei: [
        {
          value: "已成单",
          label: "已成单",
        },
        {
          value: "未成单",
          label: "未成单",
        },
      ],
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        workDate: "",
        pageNo: 1,
        pageSize: 10,
        startTime: "",
        endTime: "",
      },
      chengdan: [],
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 表单校验
      rules: {
        roleName: [
          { required: true, message: "角色名称不能为空", trigger: "blur" },
        ],
        roleKey: [
          { required: true, message: "权限字符不能为空", trigger: "blur" },
        ],
        roleSort: [
          { required: true, message: "角色顺序不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },

  methods: {
    handleUpdatse() {
      // 假设 ids 是一个包含多个元素的数组
      Promise.all(
        this.ids.map((item) => {
          // 假设 keudi 是一个返回 promise 的函数
          return kethe({ recordId: item, checkStatus: "无误" });
        })
      )
        .then((results) => {
          this.getList();
          // 所有请求都成功完成，results 是一个包含所有请求结果的数组
          this.$modal.msgSuccess("核对成功");
        })
        .catch((error) => {
          // 如果有任何一个请求失败，则进入这里
          console.error("请求失败:", error);
        });
    },
    xundan() {
      addsrenwuj(this.srer).then(()=>{
        this.$modal.msgSuccess("备注成功");
        this.yus=false
        this.getList()
      })
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      xieshou(this.queryParams).then((response) => {
        this.roleList = response.rows;
        // this.total = response.total;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
      this.reset();
    },
    // 表单重置
    reset() {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([]);
      }
      (this.menuExpand = false),
        (this.menuNodeAll = false),
        (this.deptExpand = true),
        (this.deptNodeAll = false),
        (this.form = {
          complaintId: undefined,
          roleName: undefined,
          roleKey: undefined,
          roleSort: 0,
          status: "0",
          menuIds: [],
          deptIds: [],
          menuCheckStrictly: true,
          deptCheckStrictly: true,
          remark: undefined,
        });
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.startTime = "";
      this.queryParams.endTime = "";
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.recordId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleDataScope":
          this.handleDataScope(row);
          break;
        case "handleAuthUser":
          this.handleAuthUser(row);
          break;
        default:
          break;
      }
    },
    // 树权限（展开/折叠）

    guanbishoukan() {
      this.srer = {
        remark:''
      };
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.kesuwanfrom.workDate = this.timestampToDateString(+new Date());
      this.xunkong = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      kethe({ recordId: row.recordId, checkStatus: "无误" }).then(() => {
        this.$modal.msgSuccess("核对成功");
        this.getList();
      });
    },

    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.complaintId != undefined) {
            this.form.menuIds = this.getMenuAllCheckedKeys();
            updateRole(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.menuIds = this.getMenuAllCheckedKeys();
            addRole(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 提交按钮（数据权限） */
    submitDataScope: function () {
      if (this.form.complaintId != undefined) {
        this.form.deptIds = this.getDeptAllCheckedKeys();
        dataScope(this.form).then((response) => {
          this.$modal.msgSuccess("修改成功");
          this.openDataScope = false;
          this.getList();
        });
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.srer.remark=row.remark
      this.srer.recordId=row.recordId
      // const roleIds = row.recordId || this.ids;
      this.yus=true
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/role/export",
        {
          ...this.queryParams,
        },
        `role_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
